home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / gold22.zip / GOLD.ASM < prev    next >
Assembly Source File  |  1992-02-16  |  18KB  |  593 lines

  1.     PAGE    64,132
  2.     TITLE    GOLD key from NUMLOCK
  3.     NAME    GOLD
  4. ;
  5. ; This program maps the NUM LOCK key (scan code 45H) to F1 (scan code 3BH)
  6. ; for use with Kermit emulating a DEC VT100.
  7. ;
  8. ; Version 2.2 -    February 1992
  9. ;        Added safety checks to installation code
  10. ; Version 2.1 - June 1991
  11. ;        Changed default multiplex ID to 09FH (was 0DCH) to avoid
  12. ;        problems with some versions of the KEYB program.
  13. ; Version 2.0 - March 1991
  14. ;        SHIFT and NUM LOCK acts as normal NUM LOCK
  15. ;        ALT and NUM LOCK inverts current GOLD status
  16. ;        Fix for problem with some clone BIOSes
  17. ;        Fix non-detection of BIOS intercept support
  18. ;        Use INT 09H if interrupt intercept not available
  19. ;
  20. ; Bob Eager
  21. ;    rde@ukc.ac.uk        USENET (preferred over ibmpcug)
  22. ;    rde@ibmpcug.co.uk    USENET
  23. ;    100016,2770        CompuServe
  24. ;    +44 227 367270        Telephone
  25. ;
  26. ; You may distribute this program freely as long as all of the files that
  27. ; make up the package (see the documentation file) are kept with it (including
  28. ; this source file) and you don't try to make money from it either by selling
  29. ; it directly or incorporating it into a product you sell.
  30. ;
  31. ; Values for exit status:
  32. ;
  33. ;    0    - success
  34. ;    1    - could not install program
  35. ;    2    - no BIOS support present
  36. ;    3    - unsupported DOS version (< 3.0)
  37. ;    4    - invalid parameter
  38. ;
  39. ; Constants
  40. ; ---------
  41. ;
  42.     CR    = 0DH            ; Carriage return
  43.     LF    = 0AH            ; Linefeed
  44.     TAB    = 09H            ; Tab
  45. ;
  46.     ID    = 0DCH            ; Multiplex ID
  47. ;
  48.     CSEG    SEGMENT BYTE PUBLIC 'CODE'
  49. ;
  50.     $BEGIN    EQU    $
  51. ;
  52.     ORG    0100H
  53. ;
  54.     ASSUME    CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
  55. ;
  56.     SUBTTL    Data areas
  57.     PAGE+
  58. ;
  59. ; The following jump to the initialisation code also provides three bytes
  60. ; of storage, two of which are used later by the resident part of the code.
  61. ;
  62. BEGIN:    JMP    INIT            ; jump to initialisation code
  63. ;
  64. ; Redefine storage for the above jump
  65. ;
  66.     ORG    BEGIN
  67. MBIT    EQU    THIS BYTE        ; Make/Break bit
  68.     ORG    BEGIN+1
  69. ONOFF    EQU    THIS BYTE        ; On/Off flag (0=off, initially on)
  70. ;
  71. ; Back to normal storage allocation
  72. ;
  73.     ORG    BEGIN+3
  74. ;
  75. ; The following three values may be changed if required. MPID is the multiplex
  76. ; ID, and will only need alteration if some other TSR is using the same value.
  77. ; Choose another at random until it works! NEWKEY is the scan code value for
  78. ; the key to replace NUM LOCK. MODE is used to force a particular operation
  79. ; mode; it is particularly useful when a BIOS says that it supports the
  80. ; keyboard intercept function, but doesn't.
  81. ;
  82. MPID    DB    09FH            ; 102H Multiplex ID ** DO NOT MOVE **
  83. NEWKEY    DB    03BH            ; 103H Replacement key ** DO NOT MOVE **
  84. MODE    DB    0            ; 104H Mode selector ** DO NOT MOVE **
  85.                     ;    00H = auto
  86.                     ;    01H = use INT 15H
  87.                     ;    02H = use INT 09H
  88. ;
  89. INTOFF    DW    ?            ; Old interrupt vector offset
  90. INTSEG    DW    ?            ; Old interrupt vector segment
  91. I2FOFF    DW    ?            ; Old INT 2FH offset
  92. I2FSEG    DW    ?            ; Old INT 2FH segment
  93. ;
  94.     SUBTTL    INT 2FH (multiplex) handler
  95.     PAGE+
  96. ;
  97. ; This INT 2FH handler is hooked into the MS-DOS multiplex interrupt.
  98. ;
  99. ;    Input parameters:
  100. ;
  101. ;        AH    = handler ID (MPID for this program)
  102. ;              Calls with unrecognised handler IDs are passed on
  103. ;        AL    = function code
  104. ;                00    - get installation status
  105. ;                01    - get GOLD status
  106. ;                02    - set GOLD status
  107. ;
  108. ;    Output parameters:
  109. ;
  110. ;        AL    = result
  111. ;                Get installation status:
  112. ;                    FFH    - Already installed
  113. ;                Get GOLD status:
  114. ;                    00H    - OFF
  115. ;                    01H    - ON
  116. ;                Set GOLD status:
  117. ;                    00H    - OK
  118. ;
  119. I2FHAN    PROC    FAR
  120. ;
  121.     ASSUME    CS:CSEG,DS:NOTHING,ES:NOTHING,SS:NOTHING
  122. ;
  123.     CMP    AH,MPID            ; for this program?
  124.     JE    I2FH10            ; j if so
  125.     JMP    DWORD PTR I2FOFF    ; else use old handler
  126. ;
  127. I2FH10:    OR    AL,AL            ; AL=0, get installation status?
  128.     JNE    I2FH20            ; j if not
  129.     MOV    AL,0FFH            ; indicate already installed
  130.     IRET                ; and return
  131. ;
  132. I2FH20:    DEC    AL            ; AL=1, get GOLD status?
  133.     JNE    I2FH30            ; j if not
  134.     MOV    AL,ONOFF        ; get value
  135.     IRET                ; and return
  136. ;
  137. I2FH30:    DEC    AL            ; AL=2, set GOLD status?
  138.     JNE    I2FH40            ; j if not
  139.     MOV    ONOFF,DL        ; set new value, drop through
  140. ;
  141. I2FH40:    IRET                ; and return
  142. ;
  143. I2FHAN    ENDP
  144. ;
  145.     SUBTTL    INT 15H (system services) handler
  146.     PAGE+
  147. ;
  148. ; This INT 15H handler is hooked into the BIOS system services interrupt.
  149. ; It is used only if the keyboard interrupt intercept capability is available
  150. ; in the BIOS.
  151. ;
  152. ;    Input parameters:
  153. ;        AH    - function. Only 4FH (keyboard intercept) is handled;
  154. ;              other values cause the action to be passed to the
  155. ;              previous handler.
  156. ;        AL    - scan code for key just pressed
  157. ;
  158. ;    Output parameters:
  159. ;        AL    - input scan code, or mapped version of it.
  160. ;        CY    - set to indicate that keystroke is to be processed.
  161. ;        All other register contents are preserved.
  162. ;
  163.     ASSUME    CS:CSEG,DS:NOTHING,ES:NOTHING,SS:NOTHING
  164. ;
  165. I15HAN    PROC    FAR
  166. ;
  167.     CMP    AH,4FH            ; keyboard intercept function?
  168.     JE    I15H10            ; j if so
  169.     JMP    DWORD PTR INTOFF    ; else call old handler
  170. ;
  171. I15H10:    PUSH    AX            ; save register
  172.     MOV    AH,AL            ; copy scan code
  173.     AND    AH,80H            ; isolate make/break bit
  174.     MOV    MBIT,AH            ; save it
  175.     AND    AL,7FH            ; mask out make/break bit
  176.     CMP    AL,45H            ; NUM LOCK?
  177.     JNE    I15H60            ; j if not - just return
  178. ;
  179. ; NUM LOCK has been pressed. Check for SHIFT (retain normal action).
  180. ;
  181.     PUSH    DS            ; save segment
  182.     MOV    AX,40H            ; BIOS data segment
  183.     MOV    DS,AX            ; address BIOS data segment
  184.     MOV    AL,DS:[17H]        ; get keyboard flags
  185.     POP    DS            ; recover segment
  186.     AND    AL,0FH            ; mask out lock status
  187.     MOV    AH,AL            ; take copy for later comparison
  188.     CMP    ONOFF,0            ; is GOLD on?
  189.     JE    I15H20            ; j if not - do nothing here
  190.     AND    AL,03H            ; mask out ALT and CTRL status
  191.     JE    I15H20            ; j if not shifted
  192.     CMP    AH,AL            ; see if just SHIFT
  193.     JE    I15H60            ; if so, treat as normal NUM LOCK call
  194. ;
  195. ; Check for ALT (invert GOLD status). This needs to work whether GOLD is
  196. ; ON or OFF.
  197. ;
  198. I15H20:    MOV    AL,AH            ; recover shift status bits
  199.     AND    AL,08H            ; mask out CTRL and SHIFT status
  200.     JE    I15H40            ; j if not ALT - pass through
  201.     CMP    AH,AL            ; see if just ALT
  202.     JNE    I15H40            ; j if not - pass through
  203.     TEST    MBIT,80H        ; make operation?
  204.     JNE    I15H30            ; j if not - ignore
  205.     XOR    ONOFF,1            ; flip GOLD ON/OFF flag
  206. ;
  207. I15H30:    CLC                ; absorb keystroke
  208.     POP    AX            ; recover register
  209.     RETF    2            ; return, preserving flags
  210. ;
  211. I15H40:    CMP    ONOFF,0            ; is GOLD on?
  212.     JE    I15H60            ; j if not - do nothing
  213. ;
  214. I15H50:    POP    AX            ; recover register
  215.     MOV    AL,NEWKEY        ; set replacement scan code
  216.     OR    AL,MBIT            ; include make/break bit, drop through
  217.     STC                ; make sure keystroke processed
  218.     RETF    2            ; return, preserving flags
  219. ;
  220. I15H60:    STC                ; make sure keystroke processed
  221.     POP    AX            ; recover register
  222.     RETF    2            ; return, preserving flags
  223. ;
  224. I15HAN    ENDP
  225. ;
  226. I15LEN    =    $ - I15HAN        ; length of INT 15H handler
  227. ;
  228.     SUBTTL    INT 09H (keyboard interrupt) handler
  229.     PAGE+
  230. ;
  231. ; This INT 09H handler is hooked into the keyboard interrupt vector.
  232. ; It is used only if the keyboard interrupt intercept facility is not
  233. ; available in the BIOS, and is moved in memory so that the space occupied
  234. ; by the INT 15H handler is not wasted.
  235. ;
  236. ;    Input parameters:
  237. ;        No explicit inputs. Implicit input from the keyboard
  238. ;        hardware.
  239. ;
  240. ;    Output parameters:
  241. ;        No explicit outputs. Control is passed to the normal keyboard
  242. ;        interrupt handler unless the keystroke is to be modified or
  243. ;        absorbed. Modified keystrokes are placed into the BIOS input
  244. ;        buffer.
  245. ;        All registers are preserved.
  246. ;
  247. I09HAN    PROC    FAR
  248. ;
  249.     PUSH    AX            ; save register
  250.     IN    AL,60H            ; get next character from hardware
  251.     MOV    AH,AL            ; copy scan code
  252.     AND    AH,80H            ; isolate make/break bit
  253.     MOV    MBIT,AH            ; save it
  254.     AND    AL,7FH            ; mask out make/break bit
  255.     CMP    AL,45H            ; NUM LOCK?
  256.     JE    I09H10            ; j if so
  257.     JMP    I09H80            ; else just pass on to original handler
  258. ;
  259. ; NUM LOCK has been pressed. Check for SHIFT (retain normal action).
  260. ;
  261. I09H10:    PUSH    DS            ; save segment
  262.     MOV    AX,40H            ; BIOS data segment
  263.     MOV    DS,AX            ; address BIOS data segment
  264.     MOV    AL,DS:[17H]        ; get keyboard flags
  265.     POP    DS            ; recover segment
  266.     AND    AL,0FH            ; mask out lock status
  267.     MOV    AH,AL            ; take copy for later comparison
  268.     CMP    ONOFF,0            ; is GOLD on?
  269.     JE    I09H20            ; j if not - do nothing here
  270.     AND    AL,03H            ; mask out ALT and CTRL status
  271.     JE    I09H20            ; j if not shifted
  272.     CMP    AH,A